<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
require_once 'Base/BaseHospital.class.php';

Class Hospital {

	public function  __construct() {
			if( true == isset( $_SERVER['connection'] ) ) {
				$this->connection = $_SERVER['connection'];
			}
	}

	
	/*******************************************************************************************
	******************************** Fetch Functions *******************************************
	*******************************************************************************************/

	public function fetchSql( $strSql ) {
		$result = $this->connection->RunQuery( $strSql );
		$arrobjHospital = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objHospital = new BaseHospital();
			$objHospital->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objHospital->setName( ( true == isset( $row["name"] ) ) ? $row["name"] : 'NULL' );
			$objHospital->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objHospital->setAddressLine1( ( true == isset( $row["address_line1"] ) ) ? $row["address_line1"] : 'NULL' );
			$objHospital->setAddressLine2( ( true == isset( $row["address_line2"] ) ) ? $row["address_line2"] : 'NULL' );
			$objHospital->setAddressLine3( ( true == isset( $row["address_line3"] ) ) ? $row["address_line3"] : 'NULL' );
			$objHospital->setArea( ( true == isset( $row["area"] ) ) ? $row["area"] : 'NULL' );
			$objHospital->setCity( ( true == isset( $row["city"] ) ) ? $row["city"] : 'NULL' );
			$objHospital->setPinCode( ( true == isset( $row["pin_code"] ) ) ? $row["pin_code"] : 'NULL' );
			$objHospital->setAddressDetails( ( true == isset( $row["address_details"] ) ) ? $row["address_details"] : 'NULL' );
			$objHospital->setPrimaryPhoneNumber( ( true == isset( $row["primary_phone_number"] ) ) ? $row["primary_phone_number"] : 'NULL' );
			$objHospital->setEmailAddress( ( true == isset( $row["email_address"] ) ) ? $row["email_address"] : 'NULL' );
			$objHospital->setWebUrl( ( true == isset( $row["web_url"] ) ) ? $row["web_url"] : 'NULL' );
			$objHospital->setAlternativeNumber( ( true == isset( $row["alternative_number"] ) ) ? $row["alternative_number"] : 'NULL' );
			array_push( $arrobjHospital, $objHospital );
		}
		return $arrobjHospital;
	}
	public function fetchAllHospital() {
		$result = $this->connection->RunQuery("SELECT * FROM HOSPITAL");
		$arrobjHospital = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objHospital = new BaseHospital();
			$objHospital->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objHospital->setName( ( true == isset( $row["name"] ) ) ? $row["name"] : 'NULL' );
			$objHospital->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objHospital->setAddressLine1( ( true == isset( $row["address_line1"] ) ) ? $row["address_line1"] : 'NULL' );
			$objHospital->setAddressLine2( ( true == isset( $row["address_line2"] ) ) ? $row["address_line2"] : 'NULL' );
			$objHospital->setAddressLine3( ( true == isset( $row["address_line3"] ) ) ? $row["address_line3"] : 'NULL' );
			$objHospital->setArea( ( true == isset( $row["area"] ) ) ? $row["area"] : 'NULL' );
			$objHospital->setCity( ( true == isset( $row["city"] ) ) ? $row["city"] : 'NULL' );
			$objHospital->setPinCode( ( true == isset( $row["pin_code"] ) ) ? $row["pin_code"] : 'NULL' );
			$objHospital->setAddressDetails( ( true == isset( $row["address_details"] ) ) ? $row["address_details"] : 'NULL' );
			$objHospital->setPrimaryPhoneNumber( ( true == isset( $row["primary_phone_number"] ) ) ? $row["primary_phone_number"] : 'NULL' );
			$objHospital->setEmailAddress( ( true == isset( $row["email_address"] ) ) ? $row["email_address"] : 'NULL' );
			$objHospital->setWebUrl( ( true == isset( $row["web_url"] ) ) ? $row["web_url"] : 'NULL' );
			$objHospital->setAlternativeNumber( ( true == isset( $row["alternative_number"] ) ) ? $row["alternative_number"] : 'NULL' );
			array_push( $arrobjHospital, $objHospital);
		}
		return $arrobjHospital;
	}
	public function fetchAllHospitalByIds( $arrintIds ) {
		$result = $this->connection->RunQuery("SELECT * FROM HOSPITAL WHERE id IN ( implode( "," $arrintIds ) " );
		$arrobjHospital = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objHospital->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objHospital->setName( ( true == isset( $row["name"] ) ) ? $row["name"] : 'NULL' );
			$objHospital->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objHospital->setAddressLine1( ( true == isset( $row["address_line1"] ) ) ? $row["address_line1"] : 'NULL' );
			$objHospital->setAddressLine2( ( true == isset( $row["address_line2"] ) ) ? $row["address_line2"] : 'NULL' );
			$objHospital->setAddressLine3( ( true == isset( $row["address_line3"] ) ) ? $row["address_line3"] : 'NULL' );
			$objHospital->setArea( ( true == isset( $row["area"] ) ) ? $row["area"] : 'NULL' );
			$objHospital->setCity( ( true == isset( $row["city"] ) ) ? $row["city"] : 'NULL' );
			$objHospital->setPinCode( ( true == isset( $row["pin_code"] ) ) ? $row["pin_code"] : 'NULL' );
			$objHospital->setAddressDetails( ( true == isset( $row["address_details"] ) ) ? $row["address_details"] : 'NULL' );
			$objHospital->setPrimaryPhoneNumber( ( true == isset( $row["primary_phone_number"] ) ) ? $row["primary_phone_number"] : 'NULL' );
			$objHospital->setEmailAddress( ( true == isset( $row["email_address"] ) ) ? $row["email_address"] : 'NULL' );
			$objHospital->setWebUrl( ( true == isset( $row["web_url"] ) ) ? $row["web_url"] : 'NULL' );
			$objHospital->setAlternativeNumber( ( true == isset( $row["alternative_number"] ) ) ? $row["alternative_number"] : 'NULL' );
			array_push( $arrobjHospital, $objHospital );
		}
		return $arrobjHospital;
	}

	public function fetchHospitalById( $intId ) {
		$result = $this->connection->RunQuery( "SELECT * FROM HOSPITAL WHERE id = " . $intId );
			$objHospital = NULL;
		while($row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objHospital = new BaseHospital();
			$objHospital->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objHospital->setName( ( true == isset( $row["name"] ) ) ? $row["name"] : 'NULL' );
			$objHospital->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objHospital->setAddressLine1( ( true == isset( $row["address_line1"] ) ) ? $row["address_line1"] : 'NULL' );
			$objHospital->setAddressLine2( ( true == isset( $row["address_line2"] ) ) ? $row["address_line2"] : 'NULL' );
			$objHospital->setAddressLine3( ( true == isset( $row["address_line3"] ) ) ? $row["address_line3"] : 'NULL' );
			$objHospital->setArea( ( true == isset( $row["area"] ) ) ? $row["area"] : 'NULL' );
			$objHospital->setCity( ( true == isset( $row["city"] ) ) ? $row["city"] : 'NULL' );
			$objHospital->setPinCode( ( true == isset( $row["pin_code"] ) ) ? $row["pin_code"] : 'NULL' );
			$objHospital->setAddressDetails( ( true == isset( $row["address_details"] ) ) ? $row["address_details"] : 'NULL' );
			$objHospital->setPrimaryPhoneNumber( ( true == isset( $row["primary_phone_number"] ) ) ? $row["primary_phone_number"] : 'NULL' );
			$objHospital->setEmailAddress( ( true == isset( $row["email_address"] ) ) ? $row["email_address"] : 'NULL' );
			$objHospital->setWebUrl( ( true == isset( $row["web_url"] ) ) ? $row["web_url"] : 'NULL' );
			$objHospital->setAlternativeNumber( ( true == isset( $row["alternative_number"] ) ) ? $row["alternative_number"] : 'NULL' );
		}
		return $objHospital;
	}

	public function GetKeysOrderBy($column, $order){
		$keys = array(); $i = 0;
		$result = $this->connection->RunQuery("SELECT id from hospital order by $column $order");
			while($row = $result->fetch_array(MYSQLI_ASSOC)){
				$keys[$i] = $row["id"];
				$i++;
			}
	return $keys;
	}

	public function endHospital(){
		$this->connection->CloseMysql();
	}

}